initialize - process message - RETURN
  IFZ sub[] THEN GOSUB Initialize
  IF XuiProcessMessage (grid, message, @v0, @v1, @v2, @v3, @r0, @r1, XuiDialog2B) THEN RETURN
  IF (message <= upperMessage) THEN GOSUB @sub[message]
  RETURN

Lines 20-23 initialize the grid type and basic grid function variables, invoke the appropriate routines to process the message, and return.

initialize
  IFZ sub[] THEN GOSUB Initialize

The first time a grid function is entered, it must initialize certain variables and register its grid type. sub[] is a local variable and is therefore empty the first time the function is entered.  This line calls the Initialize subroutine the first time the function is entered, but never again since sub[] is dimensioned in the subroutine.

process message with message processing function
  IF XuiProcessMessage (grid, message, @v0, @v1, @v2, @v3, @r0, @r1, XuiDialog2B) THEN RETURN

In typical grid functions, most messages are ignored or processed by a message processing function called by XuiProcessMessage().  The message processing functions for the grid function are established in the Initialize subroutine.

If the r0 argument is not zero, the message is for a kid of the grid, and XuiProcessMessage() sends the message on to the kid.  The return value of XuiProcessMessage() is the kid number the message was sent to, so this line returns from the grid function if the message was sent to a kid of the grid, not the grid itself, thus preventing the grid function from receiving a message intended for a kid and not itself.

process message with message processing subroutine
  GOSUB @sub[message]

If a message processing subroutine is defined for a particular message, GOSUB @sub[message] line calls the subroutine.

done
  RETURN

Return to the routine that called the grid function.